Next | Prev | Up | Top | Contents | Index

Using Gang Scheduling

You have been advised to design a real-time program as a family of cooperating, lightweight processes sharing an address space (see, for example, "Lightweight Process Creation With sproc()"). These processes typically coordinate their actions using locks or semaphores ("Interprocess Communication").

When process A attempts to seize a lock that is held by process B, one of two things will happen, depending on whether or not process is B is running concurrently in another CPU.

In a system with many processes, the first scenario is common even when processes A, B, and their siblings have real-time priorities. Clearly it would be better if processes A and B were always dispatched concurrently.

Gang scheduling achieves this. Any process in a share group can initiate gang scheduling. Then all the processes that share that address space are scheduled as a unit, using the priority of the highest-priority process in the gang. IRIX tries to ensure that all the members of the share group are dispatched when any one of them is dispatched.

You initiate gang scheduling with a call to schedctl(), as sketched in Example 6-4

Example 6-4 : Initiating Gang Scheduling

if (-1 == schedctl(SCHEDMODE,SGS_GANG))
{
   if (EPERM == errno)
      fprintf(stderr,"You forget to suid again\n");
   else
      perror("schedctl");
}
You can turn gang scheduling off again with another call, passing SGS_FREE in place of SGS_GANG.

Tip: Gang-scheduled processes are queued in one of the two gang queues (see "Scheduler Queues"). You can use pset to assign a set of CPUs to work only on the gang queues (see "Assigning a Processor Set to a Queue").


Next | Prev | Up | Top | Contents | Index